package gameSite;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AdminCustomerInfo
 */
@WebServlet("/AdminCustomerInformation")
public class AdminCustomerInformation extends HttpServlet {
	private static final long serialVersionUID = 1L;
	Connection conn;
	Statement stmt = null;
	ResultSet rs = null;
	User customer;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminCustomerInformation() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		getCustomerInfo(request);
		request.getRequestDispatcher("admincustomerinfo.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	protected void getCustomerInfo(HttpServletRequest request){

		String UserID = request.getParameter("id");
		String sql, result="";
		customer = new User();
		int count = 0;
      System.out.println("Creating statement...");
      try{
	      stmt = RemoteConnection.getConnection().createStatement();
	      sql = "SELECT UserID, userName, firstName, lastName, address, postalCode FROM Users where UserID = '"+UserID+"'";
	      rs = stmt.executeQuery(sql);
	      while (rs.next()){
	    	  customer = new User();
	    	  customer.setUserID(Integer.parseInt(rs.getString("UserID")));
	    	  customer.setUserName(rs.getString("userName"));
	    	  customer.setFirstName(rs.getString("firstName"));
	    	  customer.setLastName(rs.getString("lastName"));
	    	  customer.setAddress(rs.getString("address"));
	    	  customer.setPostalCode("postalCode");
	      }
	      rs.close();
	      stmt.close();
	      RemoteConnection.closeConnection();
	      request.setAttribute("UserID", customer.getUserID());
	      request.setAttribute("UserName", customer.getUserName());
	      request.setAttribute("FirstName", customer.getFirstName());
	      request.setAttribute("LastName", customer.getLastName());
	      request.setAttribute("Address", customer.getAddress());
	      request.setAttribute("PostalCode", customer.getPostalCode());
	      
      }
      catch(SQLException se){
	      //Handle errors for JDBC
	      se.printStackTrace();
	   }
		
	}
}
